Load image processing library


In [ ]:
library(magick)

Load image


In [9]:
im1 <- image_read('/opt/eodata/Landsat-5/TM/L1T/2011/07/15/LS05_RMTI_TM__GTC_1P_20110715T093254_20110715T093322_145580_0190_0023_F030/LS05_RMTI_TM__GTC_1P_20110715T093254_20110715T093322_145580_0190_0023_F030.BP.PNG')
print(im1)


  format width height colorspace matte filesize density
1    PNG  1448   1363       sRGB  TRUE  3381544   72x72

Filters and effects


In [17]:
image_negate(im1)
#image_oilpaint(frink)
#image_charcoal(frink)
#image_noise(frink)
#image_oilpaint(frink)


  format width height colorspace matte filesize density
1    PNG  1448   1363       sRGB  TRUE        0   72x72

Convolution with user defined kernel


In [7]:
kern <- matrix(0, ncol = 3, nrow = 3)
kern[1, 2] <- 0.25
kern[2, c(1, 3)] <- 0.25
kern[3, 2] <- 0.25
kern


0.000.250.00
0.250.000.25
0.000.250.00

In [12]:
img_blurred <- image_convolve(im1, kern)
img_blurred


  format width height colorspace matte filesize density
1    PNG  1448   1363       sRGB  TRUE        0   72x72

Compare blurred image to source


In [66]:
image_compare(im1,img_blurred)


  format width height colorspace matte filesize density
1    PNG  1448   1363       sRGB FALSE        0   72x72

Convolution with standard kernels

Help and list of standard kernels can be found here: http://www.imagemagick.org/Usage/convolve/


In [14]:
im1 %>% image_convolve('Sobel') %>% image_negate()


  format width height colorspace matte filesize density
1    PNG  1448   1363       sRGB  TRUE        0   72x72

In [24]:
image_crop(im1, "100x150+500x500")#: crop out width:100px and height:150px starting +500x500px


  format width height colorspace matte filesize density
1    PNG   100    150       sRGB  TRUE        0   72x72

In [31]:
im1_scaled<-image_scale(im1, "200")#: resize proportionally to width: 200px
im1_scaled
#image_scale(image, "x200"): resize proportionally to height: 200px


  format width height colorspace matte filesize density
1    PNG   200    188       sRGB  TRUE        0   72x72

In [30]:
image_border(im1, "red", "20x10")#: adds a border of 20px left+right and 10px top+bottom


  format width height colorspace matte filesize density
1    PNG  1488   1383       sRGB  TRUE        0   72x72